package com.hcrazy.manchester.app.jdbc;

import java.util.List;

import com.hcrazy.manchester.app.pojo.GroupUser;

public class GroupUserDAO extends BaseDAO<GroupUser>{

	/**
	 * 加入小组
	 * @param gUser
	 * @throws Exception
	 */
	public void addGroupUser(GroupUser gUser) throws Exception{
		StringBuilder sb = new StringBuilder();
		sb.append("insert into him_forum_groupuser(");
		sb.append("groupId,userId,username,status,joindateline");
		sb.append(" ) values (");
		sb.append(":groupId,:userId,:username,:status,:joindateline");
		sb.append(")");
		
		update(sb.toString(), gUser);
	}
	
	/**
	 * 审核通过
	 * @param groupId
	 * @param userId
	 * @throws Exception
	 */
	public void apply(long groupId,long userId) throws Exception{
		StringBuilder sb = new StringBuilder();
		sb.append("update him_forum_groupuser set ");
		sb.append(" status = 1");
		sb.append(" where groupId = ? and userId = ?");
		
		commonUpdate(sb.toString(), groupId,userId);
	}
	
	/**
	 * 审核忽略（拒绝）
	 * @param groupId
	 * @param userId
	 * @throws Exception
	 */
	public void refuse(long groupId,long userId) throws Exception{
		StringBuilder sb = new StringBuilder();
		sb.append("delete from him_forum_groupuser");
		sb.append(" where groupId = ? and userId = ?");
		
		commonUpdate(sb.toString(), groupId,userId);
	}
	
	/**
	 * 获取成员的信息列表
	 * @param groupId
	 * @return
	 * @throws Exception
	 */
	public List<GroupUser> getGroupUsers(long groupId,int status) throws Exception{
		String sql = "select * from him_forum_groupuser where groupId = ? and status = ?";
		return getList(sql, GroupUser.class, groupId,status);
	}
}
